using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;

namespace Kenly.DBFramework.ORMCodeHelper
{
    [Serializable]
    public class DataSource
    {
        private string _connectionString;
        private string _key;
        
        public string Key
        {
            get
            {
                return _key;
            }
            set
            {
                _key = value;
            }
        }

        public string ConnectionString
        {
            get
            {
                return _connectionString;
            }
            set
            {
                _connectionString = value;
            }
        }

        public static void Serialize(string filePath, DataSource[] dataSources)
        {
            ConfigSerializer.Serialize(filePath, dataSources);
        }

        public static List<DataSource> Deserialize(string filePath)
        {
            object obj = ConfigSerializer.Deserialize(filePath, typeof(DataSource[]));
            List<DataSource> dataSources = new List<DataSource>(); 

            if (obj == null)
            {
                return dataSources;
            }

            dataSources.AddRange(obj as DataSource[]);

            return dataSources;

        }
    }
}
